<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <ul>
      <li v-for="item in items" :key="item.id">
        <h4>商品名字{{item.name}}</h4>
        <img :src="item.pic" alt="">
        <p>商品价格： {{item.minPrice}}</p>
      </li>
    </ul>
    <ul>
      <li v-for="cate in cates" :key="cate.id">
        <h4>{{cate.name}}</h4>
        <img :src="cate.icon" alt="" srcset="">
      </li>
    </ul>
  </div>
  <script src="./vue.js"></script>
  <script src="./axios.js"></script>
  <script>
    // https://api.it120.cc/conner
    // 通过defaults属性定义所有的请求的baseURL

    axios.defaults.baseURL = 'https://api.it120.cc/conner';
    const vm = new Vue({
      el: '#app',
      data: {
        items: [],
        cates: []
      },
      methods: {
        fetchCates(){
          // 发送的是get请求
          axios.get('/shop/goods/category/all',{
            params: {
              a: 10,
              b: 30
            }
          }).then(res => {
            if(res.data.code === 0){
              this.cates = res.data.data
            }
          })
        },
        fetchItems(){
          // 在这里发送一个get请求  /shop/goods/list/v2
          axios.post('/shop/goods/list/v2',{
            c: 30,
            d: 50
          }).then(res => {
            if(res.data.code === 0) {
              this.items = res.data.data.result
            }
          })
        },
      },
      created(){
        this.fetchItems();
        this.fetchCates();
      }
    })
  </script>
</body>
</html>